package com.yunji.order.business.delay;

import com.yunji.order.business.OrderBusiness;
import com.yunji.order.domain.OrderDO;
import com.yunji.order.emuns.OrderCancelTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


/**
 * @Project: yunji-coffee
 * @Package: com.yunji.order.business.pattern
 * @Title: CloseOrder
 * @Description: 关闭订单
 * <p>
 * History:
 * Date						Version			Author			Summary
 * ========================================================================
 * 2024-04-20 16:41:16		V1.0			HuaAo		新建类
 */
@Slf4j
@Component
public class CloseOrderHandler implements BusinessHandler {

    @Resource
    private OrderBusiness orderBusiness;

    @Override
    @Transactional
    public void process(OrderDO order) {
        try {
            long createTime = order.getCreateTime().getTime();
            long currentTime = System.currentTimeMillis();
            log.info("【延时关闭订单】当前时间：{},创建时间:{},订单信息:{}", currentTime, createTime,order);
            orderBusiness.cancelOrder(order.getOrderId(), OrderCancelTypeEnum.SYSTEM);
        } catch (Exception e) {
            log.error("【延时关闭订单】订单关闭失败{}", order, e);
        }
    }
}